package ca.kooki.codesnippet.core;

import org.junit.Test;

import junit.framework.Assert;

public class TagCloudTest {


  @Test
  public void addKeywordsDoNotAddDuplicates()
  {
    String[] allKeywords = new String[] {"x","x","a"};
    TagCloud cloud = new TagCloud();
    cloud.addKeywords(allKeywords);
    
    String[] sortedKeywords = cloud.getCloud();
    Assert.assertEquals(2,sortedKeywords.length);
    Assert.assertEquals("a",sortedKeywords[0]);
    Assert.assertEquals("x",sortedKeywords[1]);
    
  }

  
  @Test
  public void addKeywordsReturnsInAlphabeticalOrder()
  {
    String[] allKeywords = new String[] {"x","z","a"};
    TagCloud cloud = new TagCloud();
    cloud.addKeywords(allKeywords);
    
    String[] sortedKeywords = cloud.getCloud();
    Assert.assertEquals(3,sortedKeywords.length);
    Assert.assertEquals("a",sortedKeywords[0]);
    Assert.assertEquals("x",sortedKeywords[1]);
    Assert.assertEquals("z",sortedKeywords[2]);
    
    
  }
  
  @Test
  public void getMagnitudeUnknownKeyword()
  {
    TagCloud cloud = new TagCloud();
    TagCloud.Magnitude magnitude = cloud.getMagnitudeOf("unknown");
    Assert.assertEquals(TagCloud.Magnitude.Smallest, magnitude);
  }
  
  @Test
  public void distributionByFive()
  {
    TagCloud cloud = new TagCloud();
    cloud.addKeywords(new String[] {"1"});
    cloud.addKeywords(new String[] {"1","2"});
    cloud.addKeywords(new String[] {"1","2","3"});
    cloud.addKeywords(new String[] {"1","2","3","4"});
    cloud.addKeywords(new String[] {"1","2","3","4","5"});
    cloud.addKeywords(new String[] {"1","2","3","4","5","6"});
    cloud.addKeywords(new String[] {"1","2","3","4","5","6","7"});
    cloud.addKeywords(new String[] {"1","2","3","4","5","6","7","8"});
    cloud.addKeywords(new String[] {"1","2","3","4","5","6","7","8","9"});
    cloud.addKeywords(new String[] {"1","2","3","4","5","6","7","8","9","10"});
    
    Assert.assertEquals(TagCloud.Magnitude.Smallest,cloud.getMagnitudeOf("10"));
    Assert.assertEquals(TagCloud.Magnitude.Small,cloud.getMagnitudeOf("9"));
    Assert.assertEquals(TagCloud.Magnitude.Small,cloud.getMagnitudeOf("8"));
    Assert.assertEquals(TagCloud.Magnitude.Small,cloud.getMagnitudeOf("7"));
    Assert.assertEquals(TagCloud.Magnitude.Medium,cloud.getMagnitudeOf("6"));
    Assert.assertEquals(TagCloud.Magnitude.Medium,cloud.getMagnitudeOf("5"));
    Assert.assertEquals(TagCloud.Magnitude.Medium,cloud.getMagnitudeOf("4"));
    Assert.assertEquals(TagCloud.Magnitude.Large,cloud.getMagnitudeOf("3"));
    Assert.assertEquals(TagCloud.Magnitude.Large,cloud.getMagnitudeOf("2"));
    Assert.assertEquals(TagCloud.Magnitude.Largest,cloud.getMagnitudeOf("1"));

    
  }
  
}
